#ifndef LEETCODE_CN_CPP_PROBLEMS_169_H
#define LEETCODE_CN_CPP_PROBLEMS_169_H

#include <vector>

using namespace std;

namespace problem_169
{

class Solution
{
public:
    int majorityElement(vector<int> &nums)
    {
        int count = 0, n = 0;
        for (auto num : nums)
        {
            if (count == 0)
            {
                n = num;
            }
            if (n == num)
            {
                count += 1;
            }
            else
            {
                count -= 1;
            }
        }
        return n;
    }
};

} // namespace problem_169

#endif //LEETCODE_CN_CPP_PROBLEMS_169_H
